<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script>
        function newDev() {
            $('#dlg').dialog('open').dialog('setTitle', '新增设备');
            $('#fm').form('clear');
            url = '/dev/saveDev';
        }
        function saveDev() {
            $('#fm').form('submit', {
                url: url,
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (result) {
                    var result = eval('(' + result + ')');
                    if (result.success) {
                        $('#dlg').dialog('close');		// close the dialog
                        $('#dg').datagrid('reload');	// reload the user data
                    } else {
                        $.messager.show({
                            title: 'Error',
                            msg: result.msg
                        });
                    }
                }
            });
        }
        function editDev(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('setTitle','修改设备信息');
                $('#fm').form('load',row);
                url = '/dev/updateDev?id='+row.devid;
            }
        }
        function removeDev(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('警告','确认要删除？',function(r){
                    if (r){
                        $.post('/dev/removeDev',{id:row.devid},function(result){
                            if (result.success){
                                $('#dg').datagrid('reload');	// reload the user data
                            } else {
                                $.messager.show({	// show error message
                                    title: 'Error',
                                    msg: result.msg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
    </script>
</head>
<body>
<% include ../public/head.html %>

<div class="container-fluid" >
    <h2><%=title%></h2>
        <table id="dg" title="设备管理" class="easyui-datagrid" style="width:1024px;"
               url="/dev/getdevs" method='get' fitColumns="true"
               toolbar="#toolbar"
               rownumbers="true" fitColumns="true" singleSelect="true">
            <thead>
            <tr>
                <th field="devid" width="50">设备ID</th>
                <th field="devmodel" width="50">设备型号</th>
                <th field="devaddress" width="50">设备地址</th>
                <th field="ownername" width="50">客户名称</th>
                <th field="projectname" width="50">项目名称</th>
            </tr>
            </thead>
        </table>
        <div id="toolbar">
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newDev()">新建设备</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editDev()">编辑设备</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeDev()">删除设备</a>
        </div>
        <div id="dlg" class="easyui-dialog" style="width:400px;height:350px;padding:10px 20px"
             closed="true" buttons="#dlg-buttons">
            <div class="ftitle">设备信息</div>
            <form id="fm" method="post">
                <div class="fitem">
                    <label>设备ID:</label>
                    <input name="devid" class="easyui-validatebox" required="true" validType="length[1,20]">
                </div>
                <div class="fitem">
                    <label>设备型号:</label>
                    <input name="devmodel" class="easyui-validatebox" required="true" validType="length[1,20]">
                </div>
                <div class="fitem">
                    <label>设备地址:</label>
                    <input name="devaddress" class="easyui-validatebox" validType="length[1,20]">
                </div>
                <div class="fitem">
                    <label>客户名称:</label>
                    <input class="easyui-combobox easyui-validatebox" validType="length[1,20]"
                           name="ownername"
                           data-options="
					url:'/user/list',
					method:'get',
					valueField:'username',
					textField:'username',
					panelHeight:'auto'">
                </div>
                <div class="fitem">
                    <label>项目名称:</label>
                    <input name="projectname" class="easyui-validatebox" validType="length[1,20]"">
                </div>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveDev()">保存</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
        </div>
</div>
</body>
</html>